From c6607054f7a67701bcc6fbf7d5a55cfc4e9cf3bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marvin=20L=C3=B6bel?= Date: Wed, 28 Oct 2015 10:20:00 +0100 Subject: [PATCH] Fixed testsuite --- tests/support/mod.rs | 9 ++++-- tests/test_cargo.rs | 22 +++++++-------- tests/test_cargo_bench.rs | 4 +-- tests/test_cargo_compile.rs | 40 +++++++++++++-------------- tests/test_cargo_compile_git_deps.rs | 15 +++++----- tests/test_cargo_compile_path_deps.rs | 11 ++++---- tests/test_cargo_cross_compile.rs | 8 +++--- tests/test_cargo_install.rs | 2 +- tests/test_cargo_new.rs | 4 +-- tests/test_cargo_package.rs | 2 +- tests/test_cargo_registry.rs | 2 +- tests/test_cargo_search.rs | 2 +- tests/test_cargo_test.rs | 4 +-- tests/test_shell.rs | 2 +- tests/tests.rs | 2 +- 15 files changed, 66 insertions(+), 63 deletions(-) diff --git a/tests/support/mod.rs b/tests/support/mod.rs index b345f2450..e3fbc619a 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -12,8 +12,9 @@ use std::usize; use url::Url; use hamcrest as ham; -use cargo::util::{process,ProcessBuilder}; +use cargo::util::ProcessBuilder; use cargo::util::ProcessError; +use cargo::util::process; use support::paths::CargoPathExt; @@ -134,7 +135,7 @@ impl ProjectBuilder { } pub fn process>(&self, program: T) -> ProcessBuilder { - let mut p = process(program).unwrap(); + let mut p = process(program); p.cwd(&self.root()) .env("HOME", &paths::home()) .env_remove("CARGO_HOME") // make sure we don't pick up an outer one @@ -550,6 +551,10 @@ pub fn path2url(p: PathBuf) -> Url { Url::from_file_path(&*p).ok().unwrap() } +pub fn cwd() -> PathBuf { + env::current_dir().unwrap() +} + pub static RUNNING: &'static str = " Running"; pub static COMPILING: &'static str = " Compiling"; pub static DOCUMENTING: &'static str = " Documenting"; diff --git a/tests/test_cargo.rs b/tests/test_cargo.rs index 04f55c6f2..f2449c04a 100644 --- a/tests/test_cargo.rs +++ b/tests/test_cargo.rs @@ -43,7 +43,7 @@ fn path() -> Vec { test!(list_commands_looks_at_path { let proj = project("list-non-overlapping"); let proj = fake_executable(proj, &Path::new("path-test"), "cargo-1"); - let mut pr = process(&cargo_dir().join("cargo")).unwrap(); + let mut pr = process(&cargo_dir().join("cargo")); pr.cwd(&proj.root()) .env("HOME", &paths::home()); @@ -58,7 +58,7 @@ test!(list_commands_looks_at_path { }); test!(find_closest_biuld_to_build { - let mut pr = process(&cargo_dir().join("cargo")).unwrap(); + let mut pr = process(&cargo_dir().join("cargo")); pr.arg("biuld").cwd(&paths::root()).env("HOME", &paths::home()); assert_that(pr, @@ -72,7 +72,7 @@ Did you mean `build`? // if a subcommand is more than 3 edit distance away, we don't make a suggestion test!(find_closest_dont_correct_nonsense { - let mut pr = process(&cargo_dir().join("cargo")).unwrap(); + let mut pr = process(&cargo_dir().join("cargo")); pr.arg("asdf").cwd(&paths::root()).env("HOME", &paths::home()); assert_that(pr, @@ -92,7 +92,7 @@ test!(override_cargo_home { git = false "#).unwrap(); - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .arg("new").arg("foo") .cwd(&paths::root()) .env("USER", "foo") @@ -107,22 +107,22 @@ test!(override_cargo_home { }); test!(cargo_help { - assert_that(process(&cargo_dir().join("cargo")).unwrap(), + assert_that(process(&cargo_dir().join("cargo")), execs().with_status(0)); - assert_that(process(&cargo_dir().join("cargo")).unwrap().arg("help"), + assert_that(process(&cargo_dir().join("cargo")).arg("help"), execs().with_status(0)); - assert_that(process(&cargo_dir().join("cargo")).unwrap().arg("-h"), + assert_that(process(&cargo_dir().join("cargo")).arg("-h"), execs().with_status(0)); - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .arg("help").arg("build"), execs().with_status(0)); - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .arg("build").arg("-h"), execs().with_status(0)); - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .arg("help").arg("-h"), execs().with_status(0)); - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .arg("help").arg("help"), execs().with_status(0)); }); diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index 143917258..c915635dd 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -33,7 +33,7 @@ test!(cargo_bench_simple { assert_that(p.cargo_process("build"), execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); assert_that(p.cargo("bench"), @@ -177,7 +177,7 @@ test!(cargo_bench_failing_test { assert_that(p.cargo_process("build"), execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); assert_that(p.cargo("bench"), diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 646b50651..89b50ea0e 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -21,7 +21,7 @@ test!(cargo_compile_simple { assert_that(p.cargo_process("build"), execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("i am foo\n")); }); @@ -327,7 +327,7 @@ test!(cargo_compile_with_warnings_in_a_dep_package { assert_that(&p.bin("foo"), existing_file()); assert_that( - process(&p.bin("foo")).unwrap(), + process(&p.bin("foo")), execs().with_stdout("test passed\n")); }); @@ -385,7 +385,7 @@ test!(cargo_compile_with_nested_deps_inferred { assert_that(&p.bin("foo"), existing_file()); assert_that( - process(&p.bin("foo")).unwrap(), + process(&p.bin("foo")), execs().with_stdout("test passed\n")); }); @@ -443,7 +443,7 @@ test!(cargo_compile_with_nested_deps_correct_bin { assert_that(&p.bin("foo"), existing_file()); assert_that( - process(&p.bin("foo")).unwrap(), + process(&p.bin("foo")), execs().with_stdout("test passed\n")); }); @@ -510,7 +510,7 @@ test!(cargo_compile_with_nested_deps_shorthand { assert_that(&p.bin("foo"), existing_file()); assert_that( - process(&p.bin("foo")).unwrap(), + process(&p.bin("foo")), execs().with_stdout("test passed\n")); }); @@ -576,7 +576,7 @@ test!(cargo_compile_with_nested_deps_longhand { assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); }); @@ -717,7 +717,7 @@ test!(crate_version_env_vars { assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); println!("bin"); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout(&format!("0-5-1 @ alpha.1 in {}\n", p.root().display()))); @@ -862,7 +862,7 @@ test!(ignore_broken_symlinks { assert_that(p.cargo_process("build"), execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("i am foo\n")); }); @@ -1067,9 +1067,9 @@ test!(explicit_examples { "#); assert_that(p.cargo_process("test").arg("-v"), execs().with_status(0)); - assert_that(process(&p.bin("examples/hello")).unwrap(), + assert_that(process(&p.bin("examples/hello")), execs().with_stdout("Hello, World!\n")); - assert_that(process(&p.bin("examples/goodbye")).unwrap(), + assert_that(process(&p.bin("examples/goodbye")), execs().with_stdout("Goodbye, World!\n")); }); @@ -1100,9 +1100,9 @@ test!(implicit_examples { "#); assert_that(p.cargo_process("test"), execs().with_status(0)); - assert_that(process(&p.bin("examples/hello")).unwrap(), + assert_that(process(&p.bin("examples/hello")), execs().with_stdout("Hello, World!\n")); - assert_that(process(&p.bin("examples/goodbye")).unwrap(), + assert_that(process(&p.bin("examples/goodbye")), execs().with_stdout("Goodbye, World!\n")); }); @@ -1120,7 +1120,7 @@ test!(standard_build_no_ndebug { "#); assert_that(p.cargo_process("build"), execs().with_status(0)); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("slow\n")); }); @@ -1139,7 +1139,7 @@ test!(release_build_ndebug { assert_that(p.cargo_process("build").arg("--release"), execs().with_status(0)); - assert_that(process(&p.release_bin("foo")).unwrap(), + assert_that(process(&p.release_bin("foo")), execs().with_stdout("fast\n")); }); @@ -1156,7 +1156,7 @@ test!(inferred_main_bin { "#); assert_that(p.cargo_process("build"), execs().with_status(0)); - assert_that(process(&p.bin("foo")).unwrap(), execs().with_status(0)); + assert_that(process(&p.bin("foo")), execs().with_status(0)); }); test!(deletion_causes_failure { @@ -1206,7 +1206,7 @@ test!(bad_cargo_toml_in_target_dir { .file("target/Cargo.toml", "bad-toml"); assert_that(p.cargo_process("build"), execs().with_status(0)); - assert_that(process(&p.bin("foo")).unwrap(), execs().with_status(0)); + assert_that(process(&p.bin("foo")), execs().with_status(0)); }); test!(lib_with_standard_name { @@ -1597,7 +1597,7 @@ test!(cargo_platform_specific_dependency_wrong_platform { p.cargo_process("build").exec_with_output().unwrap(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs()); let loc = p.root().join("Cargo.lock"); @@ -1986,7 +1986,7 @@ test!(build_multiple_packages { execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("i am foo\n")); let d1_path = &p.build_dir().join("debug").join("deps") @@ -1995,10 +1995,10 @@ test!(build_multiple_packages { .join(format!("d2{}", env::consts::EXE_SUFFIX)); assert_that(d1_path, existing_file()); - assert_that(process(d1_path).unwrap(), execs().with_stdout("d1")); + assert_that(process(d1_path), execs().with_stdout("d1")); assert_that(d2_path, existing_file()); - assert_that(process(d2_path).unwrap(), + assert_that(process(d2_path), execs().with_stdout("d2")); }); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index fcab5d846..c9b2d93c3 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -8,7 +8,6 @@ use support::{git, project, execs, main_file, path2url}; use support::{COMPILING, UPDATING, RUNNING}; use support::paths::{self, CargoPathExt}; use hamcrest::{assert_that,existing_file}; -use cargo; use cargo::util::process; fn setup() { @@ -70,7 +69,7 @@ test!(cargo_compile_simple_git_dep { assert_that(&project.bin("foo"), existing_file()); assert_that( - cargo::util::process(&project.bin("foo")).unwrap(), + process(&project.bin("foo")), execs().with_stdout("hello world\n")); }); @@ -137,7 +136,7 @@ test!(cargo_compile_git_dep_branch { assert_that(&project.bin("foo"), existing_file()); assert_that( - cargo::util::process(&project.bin("foo")).unwrap(), + process(&project.bin("foo")), execs().with_stdout("hello world\n")); }); @@ -205,7 +204,7 @@ test!(cargo_compile_git_dep_tag { assert_that(&project.bin("foo"), existing_file()); - assert_that(cargo::util::process(&project.bin("foo")).unwrap(), + assert_that(process(&project.bin("foo")), execs().with_stdout("hello world\n")); assert_that(project.cargo("build"), @@ -282,7 +281,7 @@ test!(cargo_compile_with_nested_paths { assert_that(&p.bin("parent"), existing_file()); - assert_that(cargo::util::process(&p.bin("parent")).unwrap(), + assert_that(process(&p.bin("parent")), execs().with_stdout("hello world\n")); }); @@ -354,7 +353,7 @@ test!(cargo_compile_with_meta_package { assert_that(&p.bin("parent"), existing_file()); - assert_that(cargo::util::process(&p.bin("parent")).unwrap(), + assert_that(process(&p.bin("parent")), execs().with_stdout("this is dep1 this is dep2\n")); }); @@ -1220,7 +1219,7 @@ test!(git_dep_build_cmd { assert_that(p.cargo("build"), execs().with_status(0)); - assert_that(cargo::util::process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("0\n")); // Touching bar.rs.in should cause the `build` command to run again. @@ -1230,7 +1229,7 @@ test!(git_dep_build_cmd { assert_that(p.cargo("build"), execs().with_status(0)); - assert_that(cargo::util::process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("1\n")); }); diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index b8b89fe65..319ec6e0c 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -6,8 +6,7 @@ use support::{project, execs, main_file}; use support::{COMPILING, RUNNING}; use support::paths::{self, CargoPathExt}; use hamcrest::{assert_that, existing_file}; -use cargo; -use cargo::util::{process}; +use cargo::util::process; fn setup() { } @@ -83,7 +82,7 @@ test!(cargo_compile_with_nested_deps_shorthand { assert_that(&p.bin("foo"), existing_file()); - assert_that(cargo::util::process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n").with_status(0)); println!("cleaning"); @@ -238,7 +237,7 @@ test!(cargo_compile_with_transitive_dev_deps { assert_that(&p.bin("foo"), existing_file()); - assert_that(cargo::util::process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("zoidberg\n")); }); @@ -687,7 +686,7 @@ test!(path_dep_build_cmd { assert_that(&p.bin("foo"), existing_file()); - assert_that(cargo::util::process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("0\n")); // Touching bar.rs.in should cause the `build` command to run again. @@ -702,7 +701,7 @@ test!(path_dep_build_cmd { COMPILING, p.url(), COMPILING, p.url()))); - assert_that(cargo::util::process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("1\n")); }); diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 1aae08f3c..3d4174afb 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -74,7 +74,7 @@ test!(simple_cross { execs().with_status(0)); assert_that(&p.target_bin(&target, "foo"), existing_file()); - assert_that(process(&p.target_bin(&target, "foo")).unwrap(), + assert_that(process(&p.target_bin(&target, "foo")), execs().with_status(0)); }); @@ -110,7 +110,7 @@ test!(simple_deps { execs().with_status(0)); assert_that(&p.target_bin(&target, "foo"), existing_file()); - assert_that(process(&p.target_bin(&target, "foo")).unwrap(), + assert_that(process(&p.target_bin(&target, "foo")), execs().with_status(0)); }); @@ -187,7 +187,7 @@ test!(plugin_deps { execs().with_status(0)); assert_that(&foo.target_bin(&target, "foo"), existing_file()); - assert_that(process(&foo.target_bin(&target, "foo")).unwrap(), + assert_that(process(&foo.target_bin(&target, "foo")), execs().with_status(0)); }); @@ -272,7 +272,7 @@ test!(plugin_to_the_max { execs().with_status(0)); assert_that(&foo.target_bin(&target, "foo"), existing_file()); - assert_that(process(&foo.target_bin(&target, "foo")).unwrap(), + assert_that(process(&foo.target_bin(&target, "foo")), execs().with_status(0)); }); diff --git a/tests/test_cargo_install.rs b/tests/test_cargo_install.rs index c2835792c..1729ceb46 100644 --- a/tests/test_cargo_install.rs +++ b/tests/test_cargo_install.rs @@ -19,7 +19,7 @@ fn setup() { } fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = process(&cargo_dir().join("cargo")).unwrap(); + let mut p = process(&cargo_dir().join("cargo")); p.arg(s).cwd(&paths::root()) .env("HOME", &paths::home()) .env_remove("CARGO_HOME"); diff --git a/tests/test_cargo_new.rs b/tests/test_cargo_new.rs index 398e07bec..0745ebfff 100644 --- a/tests/test_cargo_new.rs +++ b/tests/test_cargo_new.rs @@ -13,13 +13,13 @@ fn setup() { } fn my_process(s: &str) -> ProcessBuilder { - let mut p = process(s).unwrap(); + let mut p = process(s); p.cwd(&paths::root()).env("HOME", &paths::home()); return p; } fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = process(&cargo_dir().join("cargo")).unwrap(); + let mut p = process(&cargo_dir().join("cargo")); p.arg(s).cwd(&paths::root()).env("HOME", &paths::home()); return p; } diff --git a/tests/test_cargo_package.rs b/tests/test_cargo_package.rs index 6e59a3647..eff3bc76c 100644 --- a/tests/test_cargo_package.rs +++ b/tests/test_cargo_package.rs @@ -217,7 +217,7 @@ test!(package_verbose { "#) .file("a/src/lib.rs", ""); p.build(); - let mut cargo = process(&cargo_dir().join("cargo")).unwrap(); + let mut cargo = process(&cargo_dir().join("cargo")); cargo.cwd(&root).env("HOME", &paths::home()); assert_that(cargo.clone().arg("build"), execs().with_status(0)); assert_that(cargo.arg("package").arg("-v").arg("--no-verify"), diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 8209b5bb2..3665188d6 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -557,7 +557,7 @@ test!(dev_dependency_not_used { test!(login_with_no_cargo_dir { let home = paths::home().join("new-home"); fs::create_dir(&home).unwrap(); - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .arg("login").arg("foo").arg("-v") .cwd(&paths::root()) .env("HOME", &home), diff --git a/tests/test_cargo_search.rs b/tests/test_cargo_search.rs index 6e55047f1..2e269919b 100644 --- a/tests/test_cargo_search.rs +++ b/tests/test_cargo_search.rs @@ -35,7 +35,7 @@ fn setup() { } fn cargo_process(s: &str) -> ProcessBuilder { - let mut b = process(&cargo_dir().join("cargo")).unwrap(); + let mut b = process(&cargo_dir().join("cargo")); b.arg(s).cwd(&paths::root()).env("HOME", &paths::home()); b } diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index f5ebe9dcc..2c423cc32 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -31,7 +31,7 @@ test!(cargo_test_simple { assert_that(p.cargo_process("build"), execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); assert_that(p.cargo("test"), @@ -188,7 +188,7 @@ test!(cargo_test_failing_test { assert_that(p.cargo_process("build"), execs()); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")).unwrap(), + assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); assert_that(p.cargo("test"), diff --git a/tests/test_shell.rs b/tests/test_shell.rs index a2a5e5638..366215be4 100644 --- a/tests/test_shell.rs +++ b/tests/test_shell.rs @@ -81,7 +81,7 @@ test!(color_explicitly_enabled { test!(no_term { // Verify that shell creation is successful when $TERM does not exist. - assert_that(process(&cargo_dir().join("cargo")).unwrap() + assert_that(process(&cargo_dir().join("cargo")) .env_remove("TERM"), execs().with_stderr("")); }); diff --git a/tests/tests.rs b/tests/tests.rs index 612d11e03..7fe2e27d3 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -64,7 +64,7 @@ mod test_cargo_verify_project; mod test_cargo_version; mod test_shell; -thread_local!(static RUSTC: Rustc = Rustc::new("rustc").unwrap()); +thread_local!(static RUSTC: Rustc = Rustc::new("rustc", &support::cwd()).unwrap()); fn rustc_host() -> String { RUSTC.with(|r| r.host.clone()) -- 2.30.2